//
//  FeedBackView.m
//  ProjectforHDX
//
//  Created by Jaesun on 16/7/5.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "FeedBackView.h"

@implementation FeedBackView 

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self s_setupViews];
    }
    return  self;
}
- (void)s_setupViews {
    
    // 问题描述 title
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 550)];
    headView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    // 标题
    _titleLab = [[RZCustomLable alloc]initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH - 30, 40)];
    NSString *titleString = [UtilCheck language:@"setting.title"];
    if ([titleString isEqualToString:@"标题"]) {
        NSMutableAttributedString *titleAttributed = [[NSMutableAttributedString alloc]initWithString:@"标题 *"];
        [titleAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(2, 2)];
        [titleAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(2, 2)];
        _titleLab.attributedText = titleAttributed;
    }else {
        NSMutableAttributedString *titleAttributed = [[NSMutableAttributedString alloc]initWithString:@"Title *"];
        [titleAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(5, 2)];
        [titleAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 2)];
        _titleLab.attributedText = titleAttributed;
    }
    _titleLab.font = CustomFont(14);
    [headView addSubview:_titleLab];
    
    // 标题输入框
    _titleView = [[HDXTextView alloc] initWithFrame:CGRectMake(0, _titleLab.bottom, headView.width, 40)];
    [headView addSubview:_titleView];
    _titleView.layer.borderWidth=0.5;
    _titleView.layer.borderColor=[UtilCheck hexStringToColor:LineColor alpha:0.75].CGColor;
    _titleView.backgroundColor = [UIColor whiteColor];
    _titleView.font = CustomFont(14);
    _titleView.surplusLblPlaceholderSizelen = 50;

    _titleView.placeholderColor = [THMangerTool getRZColor:178 green:178 blue:178 alpha:1];
    _titleView.surplusLblPlaceholderColor= [THMangerTool getRZColor:178 green:178 blue:178 alpha:1];
    
    // 反馈类型
    _typeLable = [[RZCustomLable alloc] initWithFrame:CGRectMake(15, _titleView.bottom, SCREEN_WIDTH - 30, 40)];
    
    NSString *typeString = [UtilCheck language:@"setting.feedback"];
    if ([typeString isEqualToString:@"反馈类型"]) {
        NSMutableAttributedString *typeAttributed = [[NSMutableAttributedString alloc]initWithString:@"反馈类型 *"];
        
        [typeAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(4, 2)];
        [typeAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4, 2)];
        _typeLable.attributedText = typeAttributed;
    }else {
        NSMutableAttributedString *typeAttributed = [[NSMutableAttributedString alloc]initWithString:@"Feedback type *"];
        
        [typeAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(13, 2)];
        [typeAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(13, 2)];
        _typeLable.attributedText = typeAttributed;
    }
    _typeLable.font = CustomFont(14);
    [headView addSubview:_typeLable];
    
    // 反馈类型选择框
    UIView *feedbackView = [[UIView alloc]initWithFrame:CGRectMake(0, _typeLable.bottom, headView.width, 40)];
    feedbackView.backgroundColor = [UIColor whiteColor];

    _feedbackTypeLable = [[RZCustomLable alloc] initWithFrame:CGRectMake(15, 0, headView.width, 40)];
    _feedbackTypeLable.font = CustomFont(14);
    _feedbackTypeLable.userInteractionEnabled = YES;
    UITapGestureRecognizer *feedbackTypeRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(feedbackTypeData)];
    [_feedbackTypeLable addGestureRecognizer:feedbackTypeRecognizer];
    [feedbackView addSubview:_feedbackTypeLable];

    [headView addSubview:feedbackView];

    // 优先级
    _priorityTitleLable = [[RZCustomLable alloc] initWithFrame:CGRectMake(15, feedbackView.bottom, SCREEN_WIDTH - 30, 40)];
    NSString *priorityString = [UtilCheck language:@"setting.priority"];
    if ([priorityString isEqualToString:@"优先级"]) {
        NSMutableAttributedString *priorityTitleAttributed = [[NSMutableAttributedString alloc]initWithString:@"优先级 *"];
        [priorityTitleAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(3, 2)];
        [priorityTitleAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(3, 2)];
        _priorityTitleLable.attributedText = priorityTitleAttributed;
    }else {
        NSMutableAttributedString *priorityTitleAttributed = [[NSMutableAttributedString alloc]initWithString:@"Priority *"];
        [priorityTitleAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(8, 2)];
        [priorityTitleAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(8, 2)];
        _priorityTitleLable.attributedText = priorityTitleAttributed;
    }
    _priorityTitleLable.font = CustomFont(14);
    [headView addSubview:_priorityTitleLable];
    
    // 优先级选择框
    UIView *preorityView = [[UIView alloc]initWithFrame:CGRectMake(0, _priorityTitleLable.bottom, headView.width, 40)];
    preorityView.backgroundColor = [UIColor whiteColor];
    _priorityLable= [[RZCustomLable alloc] initWithFrame:CGRectMake(15, 0, headView.width - 15, 40)];
    _priorityLable.font = CustomFont(14);
    _priorityLable.userInteractionEnabled = YES;
    UITapGestureRecognizer *priorityRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(priorityData)];
    [_priorityLable addGestureRecognizer:priorityRecognizer];
    [preorityView addSubview:_priorityLable];

    [headView addSubview:preorityView];
    
    // 问题描述
    _textLab = [[RZCustomLable alloc] initWithFrame:CGRectMake(15, _titleView.bottom+160, SCREEN_WIDTH - 30, 40)];
    _textLab.font = CustomFont(14);

    NSString *textString = [UtilCheck language:@"setting.problemDescrip"];
    
    if ([textString isEqualToString:@"问题描述"]) {
        NSMutableAttributedString *textAttributed = [[NSMutableAttributedString alloc]initWithString:@"问题描述 *"];
        [textAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(4, 2)];
        [textAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4, 2)];
        _textLab.attributedText = textAttributed;
    }else {
        NSMutableAttributedString *textAttributed = [[NSMutableAttributedString alloc]initWithString:@"Problem Description *"];
        [textAttributed addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(19, 2)];
        [textAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(19, 2)];
        _textLab.attributedText = textAttributed;
    }
    [headView addSubview:_textLab];
    
    // 建议输入框
    _textView = [[HDXTextView alloc] initWithFrame:CGRectMake(0, _textLab.bottom, headView.width, 95)];
        [headView addSubview:_textView];
    _textView.layer.borderWidth=0.5;
    _textView.layer.borderColor=[UtilCheck hexStringToColor:LineColor alpha:0.75].CGColor;
    _textView.backgroundColor = [UIColor whiteColor];
    _textView.font = CustomFont(14);
    _textView.placeholder = [UtilCheck language:@"setting.descripPlace"];
    _textView.placeholderColor = [THMangerTool getRZColor:178 green:178 blue:178 alpha:1];
    _textView.surplusLblPlaceholderSizelen = 200;

    _textView.surplusLblPlaceholderColor= [THMangerTool getRZColor:178 green:178 blue:178 alpha:1];

    //上传图片
    _imgLab = [[RZCustomLable alloc] initWithFrame:CGRectMake(15, _textView.bottom, SCREEN_WIDTH - 30, 40)];
    _imgLab.text = [UtilCheck language:@"setting.uploadPhoto"];
    _imgLab.font = CustomFont(14);
    [headView addSubview:_imgLab];
    
    //选择图片
    UIImage *addImage = BDFILEIMAGENAEM(@"default/add_image");
    _imgBgView = [[UIView alloc] initWithFrame:CGRectMake(0, _imgLab.bottom, headView.width, addImage.size.height + 20)];
    _imgBgView.backgroundColor = [UIColor whiteColor];

    [headView addSubview:_imgBgView];
    
    _imageView = [[RZCustomImageView alloc] initWithFrame:CGRectMake(20, _imgLab.bottom + 10, addImage.size.width, addImage.size.height)];
    _imageView.image = addImage;
    [headView addSubview:_imageView];
    _imageView.userInteractionEnabled = YES;
    
    [self addSubview:headView];
    
    //按钮
    _submitBtn = [RZCustomButtom buttonWithType:(UIButtonTypeCustom)];
    _submitBtn.frame = CGRectMake(20, _imgBgView.bottom + 5, SCREEN_WIDTH - 20 * 2, 45);
    [_submitBtn setTitle:[UtilCheck language:@"setting.submit"] forState:(UIControlStateNormal)];
    [_submitBtn setBackgroundColor:[UtilCheck hexStringToColor:@"7090f8" alpha:1]];
    _submitBtn.titleLabel.font = CustomFont(16);
    _submitBtn.layer.cornerRadius = 8;
    _submitBtn.layer.masksToBounds = YES;
    [headView addSubview:_submitBtn];
    
    
}

- (void)feedbackTypeData{
    NSArray *feedbackArray = [NSArray arrayWithObjects:[UtilCheck language:@"setting.systemProblems"],[UtilCheck language:@"setting.sparePartsService"],[UtilCheck language:@"setting.consigneeOrConsignor"],[UtilCheck language:@"setting.logisticsProblems"],[UtilCheck language:@"setting.qualityProblem"],[UtilCheck language:@"setting.other"], nil];
    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"setting.pleaseFeedback"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:feedbackArray];
    AlertView.mark = 1001;
    AlertView.delegate = self;
    [AlertView show];
}
- (void)priorityData{
    NSArray *priorityArray = [NSArray arrayWithObjects:[UtilCheck language:@"setting.emergency"],[UtilCheck language:@"setting.general"], nil];
    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"setting.pleasePriority"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:priorityArray];
    AlertView.mark = 1002;
    AlertView.delegate = self;
    [AlertView show];
}

- (void)getselect:(NSString *)getselect mark:(int)mark row:(int)row
{
    if (mark == 1001) {
        _feedbackTypeLable.text = getselect;
    }else if (mark == 1002){
        _priorityLable.text = getselect;
    }
}

@end
